<!DOCTYPE html>
<html lang="en">

<head>
    <title>VUE级联选择</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <!-- <link rel="stylesheet" type="text/css" href="../../common/sui.css"> -->
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none;
        }

        .dropdown-box {
            font-size: 12px;
            line-height: 18px;
            vertical-align: middle;
            padding: 0;
            height: 24px;
            position: relative;
            display: inline-block;
        }

        .dropdown-box .dropdown-inner {
            border: 1px solid #cccccc;
            border-radius: 2px;
            display: inline-block;
        }

        .dropdown-box .dropdown-toggle {
            padding: 2px 16px 2px 8px;
            color: #666;
            min-width: 64px;
            display: block;
            position: relative;
        }

        .dropdown-box .dropdown-toggle:after {
            content: "";
            display: block;
            width: 6px;
            height: 6px;
            border-left: 1px solid #ccc;
            border-bottom: 1px solid #ccc;
            top: 6px;
            right: 6px;
            position: absolute;
            transform: rotate(-46deg);
            transition: all 0.3s ease-in;
        }

        .dropdown-box .dropdown-toggle.select:after {
            transform: rotate(134deg);
            transition: all 0.3s ease-in;
            top: 11px;
        }

        .dropdown-box .dropdown-menu {
            display: none;
            width: 100%;
            box-sizing: border-box;
            position: absolute;
            left: 0;
            padding: 1px 0;
            border-radius: 0 0 2px 2px;
            background-color: #ffffff;
            border: 1px solid #cccccc;
            max-height: 300px;
            overflow-y: auto;
        }

        .dropdown-box .dropdown-menu li {
            padding: 0 1px;
        }

        .dropdown-box .dropdown-menu li a {
            width: 100%;
            display: block;
            box-sizing: border-box;
            color: #666666;
            padding: 2px 8px;
        }

        .dropdown-box .dropdown-menu li a:hover {
            background-color: #40adf1;
            color: #fff;
        }

        .dropdown-menu::-webkit-scrollbar-track {
            box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
            background-color: #f7f7f7;
        }

        .dropdown-menu::-webkit-scrollbar {
            width: 4px;
            background-color: #f7f7f7;
        }

        .dropdown-menu::-webkit-scrollbar-thumb {
            background-color: #80848f;
            border: 1px solid #80848f;
        }
    </style>
</head>

<body>
    <div id="app" style="margin: 50px;">
        <div id="dropdown" style="width: 500px; margin: 0 auto;text-align: center;">
            <div class="dropdown-box" id="prov">
                <div class="dropdown-inner">
                    <a href="javascript:;" class="dropdown-toggle" @click="listShow('prov')"><span>{{currentProv}}</span></a>
                    <ul class="dropdown-menu">
                        <li v-for="(item, index) in provList"><a href='javascript:;' @click="select('prov', index)">{{item.name}}</a></li>
                    </ul>
                </div>
            </div>
            <div class="dropdown-box" id="city">
                <div class="dropdown-inner">
                    <a href="javascript:;" class="dropdown-toggle" @click="listShow('city')"><span>{{currentCity}}</span></a>
                    <ul class="dropdown-menu">
                        <li v-for="(item, index) in cityList"><a href='javascript:;' @click="select('city', index)">{{item.name}}</a></li>
                    </ul>
                </div>
            </div>
            <div class="dropdown-box" id="area">
                <div class="dropdown-inner">
                    <a href="javascript:;" class="dropdown-toggle" @click="listShow('area')"><span>{{currentArea}}</span></a>
                    <ul class="dropdown-menu">
                        <li v-for="(item, index) in areaList"><a href='javascript:;' @click="select('area', index)">{{item}}</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../common/jquery.min.js"></script>
    <script type="text/javascript" src="https://unpkg.com/vue@2.2.6/dist/vue.min.js"></script>
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                list: [],
                currentProv: '请选择',
                currentCity: '请选择',
                currentArea: '请选择',
                provList: [],
                cityList: [],
                areaList: []
            },
            mounted() {
                $.ajax({
                    type: "get",
                    url: '../../../area.json',
                    dataType: 'json',
                    success: (result) => {
                        this.provList = result.provList;

                    }, error: (msg) => {
                        console.log(msg);
                    }
                });
            },
            methods: {
                listShow(attr) {
                    $(".dropdown-menu").slideUp(300);
                    if (attr == "prov") {
                        $("#prov .dropdown-menu").slideDown(300);
                    } else if (attr == "city") {
                        if (this.currentProv === "请选择") {
                            alert("请先选择省份");
                            return;
                        }
                        $("#city .dropdown-menu").slideDown(300);
                    } else if (attr == "area") {
                        if (this.currentCity === "请选择") {
                            alert("请先选择城市");
                            return;
                        }
                        $("#area .dropdown-menu").slideDown(300);
                    }
                },
                select(attr, index) {
                    if (attr == "prov") {
                        $("#prov .dropdown-menu").slideUp(300);
                        this.currentProv = this.provList[index].name;
                        this.cityList = this.provList[index].cityList;
                        this.currentCity = '请选择';
                        this.currentArea = '请选择';
                    } else if (attr == "city") {

                        $("#city .dropdown-menu").slideUp(300);
                        this.currentCity = this.cityList[index].name;
                        this.areaList = this.cityList[index].areaList;
                        this.currentArea = '请选择';
                    } else if (attr == "area") {
                        $("#area .dropdown-menu").slideUp(300);
                        this.currentArea = this.areaList[index];
                    }
                }
            }
        });
    </script>
</body>

</html>